package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.DishFlavor;
import com.itheima.pojo.Setmeal;
import com.itheima.pojo.SetmealDish;
import com.itheima.pojo.SetmealDto;
import com.itheima.service.SetmealDishService;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {
    @Autowired
    private SetmealDishService dishService;
    @Override
    public Integer saveWithDish(SetmealDto setmealDto) {
        boolean save = this.save(setmealDto);
        List<SetmealDish> list=setmealDto.getSetmealDishes();
        Long id=setmealDto.getId();
        for (int i=0;i<list.toArray().length;i++){
            list.get(i).setSetmealId(id);
        }
        boolean b = dishService.saveBatch(list);
        if(save&&b){
            return 1;
        }else{
            return 0;
        }
    }
}
